import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/helper.dart';
import 'package:yp/services/api.dart';

import 'state.dart';

class FollowUpEvaluationLogic extends GetxController {
  final state = FollowUpEvaluationState();

  @override
  void onInit() {
    super.onInit();
    print('================ ${Get.arguments}');
    state.goodsStr = Get.arguments['goodsUrl'];
    state.titleStr = Get.arguments['titleStr'];
    update();
  }

  void additionalComments() {
    String imgUrl = state.imageUrlList.join(',');
    if (state.textController.text.isEmpty) {
      toast("请填写追评内容");
      return;
    }
    var params = {
      'use_platform': 2,
      'tml_num_id': Get.arguments['order_num_id'], // 订单编号
      'content': state.textController.text, // 评论内容
      'rate_pic': imgUrl, //图片
      'rate_id': Get.arguments['rate_id'], // 评价id（追评的对象）
      'shop_id': Get.arguments['shop_id'], //店铺编码
      'access_token': SpUtil.getString('token'),
    };

    print(params);
    // return;
    Api.additionalEvaluation(params).listen((event) {
      print(' 追加评论 请求结果 ===========   event = $event');
      if (event['code'] == 0) {
        toast('评论成功');
        Get.back(result: true);
      } else {
        toast('评论失败');
      }
    }, onError: (error) {
      print(' 追加评论 请求结果 -----------   error = $error');
    });
  }
}
